package com.cssw.fyzb.busi.api.live;

import com.cssw.fyzb.core.model.vo.live.LiveVo;
import com.cssw.fyzb.busi.service.live.LiveService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import com.ydn.dbframe.plugin.activerecord.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 查询直播列表
 * @author YangYiQun
 */
@Function(description = "查询直播列表", parameters = {
        @Parameter(name = "key", type = Type.String, description = "关键字搜索", required = true),
        @Parameter(name = "pageNumber", type = Type.String, description = "当前页，从1开始", required = true),
        @Parameter(name = "pageSize", type = Type.String, description = "页大小", required = true)
})
@Component
public class SearchLive implements Action {

    private static final Logger logger = LoggerFactory.getLogger(SearchLive.class);

    @Autowired
    private LiveService liveService;

    @Override
    public Response execute(Request request) throws Exception {
        String key = request.getString("key");
        Integer pageNumber = request.getInteger("pageNumber");
        Integer pageSize = request.getInteger("pageSize");
        try {
            Page<LiveVo> page = liveService.searchLive(key, pageNumber, pageSize);
            return Response.success().put("list", page.getList()).put("total", page.getTotalPage()).put("count", page.getTotalRow());
        } catch (Exception e) {
            logger.error("", e);
            return Response.fail("查询失败");
        }
    }
}
